/*
* File: som_regularizer.h
* @Brief: the functions about regularizer in SOM.
* @Author: Mr.Charley(Chinese name: Chenglin Jia).
* @Version: 1.0
* @Date: 2024/7/22
*/

#ifndef SOM_REGULARIZER_H
#define SOM_REGULARIZER_H

#include "som_base.h"

enum Som_Regularization_Type_ 
{ 
	Manual, 
	MatrixNorm 
};

typedef enum SomRegularizationType_ Som_Regularization_Type;

struct Som_Regularizer_
{
	Som_Regularization_Type regularization_type;
	double lamda;
	bool regularize_last_row;
};

typedef struct Som_Regularizer_ Som_Regularizer;

/************************************************************************/
/*
 * @brief obtain the matrix of regularizer.
 * @param[in] data: Data matrix that might be used to calculate an automatic value for lambda.
 * @param[in] num_training_elements: Number of training elements.
 * @param[in] som_regularizer: the object of som_regularizer.
 * @return Return a diagonal matrix with the same dimensions as the given data matrix.
 */
 /************************************************************************/
SOM_EXPORT CvMat* som_regularizer_get_matrix(const CvMat* data, const int num_training_element, Som_Regularizer* som_regularizer);

/************************************************************************/
/*
 * @brief Write the object Som_Regularizer into the file given.
 * @param[in] fp: The pointer of FILE to the file want to write in.
 * @param[in] som_regularizer: The object Som_Regularizer.
 * @return void.
 */
 /************************************************************************/
SOM_EXPORT void write_som_regularize_into_file(FILE* fp, const Som_Regularizer* som_regularizer);

/************************************************************************/
/*
 * @brief Read the object SomRegularizer into the file given.
 * @param[in] fp: The pointer of FILE to the file want to read from.
 * @param[in] som_regularizer: The object SomRegularizer.
 * @return Return void
 */
 /************************************************************************/
SOM_EXPORT void read_som_regularize_from_file(FILE* fp, Som_Regularizer** som_regularizer);
#endif // !SOM_REGULARIZER_H
